package de.baumann.browser.activitys.duobao

import android.content.Context
import android.content.Intent
import de.baumann.browser.R
import de.baumann.browser.adapter.CYJLAdapter
import de.baumann.browser.api.net.vo.duobao.CYJL
import de.baumann.browser.base.BaseOdinActivity
import de.baumann.browser.base.BasePresenter
import de.baumann.browser.iview.IBaseView
import de.baumann.browser.iview.duobao.ICYJLView
import de.baumann.browser.present.duobao.CYJLPresenter
import kotlinx.android.synthetic.main.activity_can_yu_record.*
import kotlinx.android.synthetic.main.include_tool_bar_2.*

class CanYuRecordActivity : BaseOdinActivity<ICYJLView, CYJLPresenter>(), ICYJLView {


    companion object {
        fun startCanYuRecordActivity(context: Context, id: String) {
            context.startActivity(Intent(context, CanYuRecordActivity::class.java).apply {
                putExtra("id", id)
            })
        }
    }

    private lateinit var cyjlAdapter: CYJLAdapter

    override fun getLayout(): Int {
        return R.layout.activity_can_yu_record
    }

    override fun getBackIcon(): Int {
        return R.drawable.ic_back
    }

    override fun getTitleText(): String {
        return "参与记录"
    }

    override fun initView() {
        initToolbar(commToolBar, commTitle)
        cyjlAdapter = CYJLAdapter()
        cyjl.adapter = cyjlAdapter
        cyjlAdapter.setOnItemClickListener { _, _, position ->
            val jl = cyjlAdapter.getItem(position)
            CanYuDetailActivity.startCanYuDetailActivity(mContext, jl!!.participationInfoId)
        }
    }

    override fun initData() {
        presenter?.cyjl()
    }

    override fun createPresenter(): CYJLPresenter {
        return CYJLPresenter()
    }

    override fun createView(): ICYJLView {
        return this
    }

    override val id: String
        get() = intent.getStringExtra("id")

    override fun setList(list: List<CYJL>) {
        cyjlAdapter.setNewData(list)
    }
}